package com.jurassic.demo.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

/**
 * @Author pan_jin
 * @Description: $
 * @Date: 2022/7/12 11:23
 * @Version: 1.0.0
 * @Slogan: 梦想还是要有的万一实现了呢
 */
@Component
public class AppService {
    @Value("classpath:app.properties")
    Resource resource;

    private String log;

    @PostConstruct
    public void init() {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) {
            this.log = reader.lines().collect(Collectors.joining("\n"));
            System.out.println("log = " + log);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
